﻿var fs = require('fs');
var util = require('util');
var path = require('path');
var moment = require('moment');
var config = require('./config.json');

moment.application_dateformat = config.application_dateformat;
config.use_debug = false;

var Bookshelf = require('bookshelf');
Bookshelf.bookshelf = Bookshelf.initialize({
    client: 'sqlite',
    connection: {
        filename: path.join(__dirname, config.db_rel_path),
    },
    debug: config.use_debug,
});

var Database = require('./app/database');
Database.initialize(
    function () {
        console.log('Database successfully created!');
        if (config.use_debug) {
            Database.createTestData(function (err) { console.log('Test Data Created'); console.log(err); });
        };
    },
    function (errors) {
        console.log('Database creation failed!');
    });

var correction = require('./temp/corrections_date');
correction.execute();
